﻿CREATE TABLE [dbo].[EnterpriseUser] (
    [UserId]          INT           IDENTITY (1, 1) NOT NULL,
    [EnterpriseId]    INT           NOT NULL,
    [UserName]        VARCHAR (150) NOT NULL,
    [FirstName]       VARCHAR (100) NULL,
    [LastName]        VARCHAR (100) NULL,
    [MiddleName]      VARCHAR (100) NULL,
    [adt_DateCreated] DATETIME      CONSTRAINT [DF_EnterpriseUser_adt_DateCreated] DEFAULT (getdate()) NOT NULL,
    [adt_CreatedBy]   VARCHAR (50)  NULL,

	--These are taken from standard ASPNET DB Membership table. If people wants to use this for authentication also, these fields will be useful
	[Password] [nvarchar](128) NULL,
	[PasswordFormat] [int] NULL,
	[PasswordSalt] [nvarchar](128) NULL,
	[Email] [nvarchar](256) NULL,
	[PasswordQuestion] [nvarchar](256) NULL,
	[PasswordAnswer] [nvarchar](128) NULL,
	[IsApproved] [bit] NOT NULL DEFAULT 1,
	[IsLockedOut] [bit] NOT NULL DEFAULT 0,
	[LastLoginDate] [datetime] NULL,
	[LastPasswordChangedDate] [datetime] NULL,
	[LastLockoutDate] [datetime] NULL,
	[FailedPasswordAttemptCount] [int]  NULL,
	[FailedPasswordAttemptWindowStart] [datetime] NULL,
	[FailedPasswordAnswerAttemptCount] [int] NULL,
	[FailedPasswordAnswerAttemptWindowsStart] [datetime] NULL,
	[Comment] [nvarchar](256) NULL,



    CONSTRAINT [PK_EnterpriseUser] PRIMARY KEY CLUSTERED ([UserId] ASC), 
    CONSTRAINT [FK_EnterpriseUser_ToTable] FOREIGN KEY ([EnterpriseId]) REFERENCES [Enterprise]([EnterpriseId])
);


GO

CREATE UNIQUE INDEX [IX_EnterpriseUser_Column] ON [dbo].[EnterpriseUser] ([UserName], [EnterpriseId])
